from django.db import models
from assest.models import Server
from django.contrib.auth.models import User
from service.models import *

# Create your models here.

class Host(models.Model):
	server = models.ForeignKey(Server, null=True, blank=True, on_delete=models.SET_NULL)
	ip = models.IPAddressField(unique=True)
	idrac = models.IPAddressField(null=True, blank=True)
	hostype = models.ForeignKey('Hostype', null=True, blank=True, on_delete=models.SET_NULL)
	hostname = models.CharField(max_length=50, null=True, blank=True)
	os = models.CharField(max_length=60, null=True, blank=True)
	kernel = models.CharField(max_length=20, null=True, blank=True)
	owner = models.ForeignKey(User, null=True)
	last_check = models.DateTimeField(auto_now_add=True)
	update_interval = models.IntegerField(max_length=10, null=True, default=5)
	status = models.IntegerField(max_length=1, default=3)	# 0:ok, 1:down, 2:retry, 3:unknown
	service = models.ManyToManyField(Service,null=True,blank=True)
	
	def __unicode__(self):
		return self.ip
	
class Hostype(models.Model):
	name = models.CharField(max_length=60)
	remark = models.CharField(max_length=255, null=True, blank=True)
	
	def __unicode__(self):
		return self.name
class Agent(models.Model):
	filename = models.CharField(max_length=100)
	version = models.CharField(max_length=10)
	remark = models.CharField(max_length=200)
	distributed = models.BooleanField(default=False)
	timestramp=models.DateTimeField(auto_now_add=True)
#	success = models.IntegerField()
#	failed = models.IntegerField()
	
	def __unicode__(self):
		return self.version
